program main

    implicit none
    real, allocatable :: x(:), y(:)

    x = [1, 2, 3]
    y = [4, 5, 6]
    print *, loc(x), loc(y)

    call swap_alloc(x, y)

    print *, x
    print *, y
    print *, loc(x), loc(y)

contains

    pure subroutine swap_alloc(x, y)
        real, allocatable, intent(inout) :: x(:), y(:)
        real, allocatable :: tmp(:)

        call move_alloc(x, tmp)
        call move_alloc(y, x)
        call move_alloc(tmp, y)

    end subroutine swap_alloc

end program main

